package com.cskaoyan.catmall.controller.background;

import com.cskaoyan.catmall.model.bo.CommentBo;
import com.cskaoyan.catmall.model.pojo.MarketComment;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.model.vo.CommentVo;
import com.cskaoyan.catmall.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 评论模块
 * 创建日期: 2022/01/09 16:50
 *
 * @author ghr
 */
@RestController
@RequestMapping("admin/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    /**
     * @param
     * @param param
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 评论列表
     * @author ghr
     * @date 2022/1/9 5:24 下午
     */
    @GetMapping("list")
    public BaseRespVo selectComment(@Validated CommentBo commentBo,BindingResult bindingResult) {
        if (bindingResult.hasFieldErrors()) {
            return BaseRespVo.fail("参数错误");
        }
        CommentVo commentVo = commentService.selectComment(commentBo);
        return BaseRespVo.ok(commentVo);
    }


    /**
     * @param
     * @param marketComment
     * @return com.cskaoyan.catmall.model.vo.BaseRespVo
     * @description 删除评论
     * @author ghr
     * @date 2022/1/9 5:25 下午
     */
    @PostMapping("delete")
    public BaseRespVo deleteComment(@RequestBody MarketComment marketComment) {
        commentService.deleteComment(marketComment);
        return BaseRespVo.ok();
    }
}